import SceneUi from "../scene/SceneUi";
import TipUi from "../tip/TipUi";
import Model from "../../common/model/Model";
import Net from "../../common/net/Net";
import Scene from "../../common/scene/Scene";

const {ccclass, property} = cc._decorator;

@ccclass
export default class LoginUi extends cc.Component {
    @property(cc.Node)
    bgNode:cc.Node=null;
    @property(cc.EditBox)
    usernameText:cc.EditBox=null;
    start() {
        var scale = Math.max(cc.winSize.width/this.bgNode.width, cc.winSize.height/this.bgNode.height)
        this.bgNode.setScale(scale);
    };
    /** 游客登录 */
    guestBtnClick () {
        // SceneUi.instance.enterMain();

        Model.clear();
        Net.connect((err)=>{
            if (err) {
                TipUi.instance.showTip("无法连接服务器");
            } else {
                Net.request(
                    "connector.entryHandler.login",
                    {username:this.usernameText.string},
                    (err, data)=>{
                    if (!err) {                    
                        console.log(data);
                        SceneUi.enterMain();
                    }
                });
            }
        });
    };
}
